package com.wn.web;

import com.wn.annotation.RequireRoles;
import com.wn.auth.JWTUtil;
import com.wn.common.Const;
import com.wn.common.PageParam;
import com.wn.ov.ConsumOv;
import com.wn.ov.UserOv;
import com.wn.pojo.Card;
import com.wn.resopnse.ResponseCode;
import com.wn.resopnse.ServerResponse;
import com.wn.service.CardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = " 就诊卡管理裂口",description=" 就诊卡管理接口")
@RestController
@RequestMapping("card")
public class CardController {

    @Autowired
    private CardService cardService;


    /** 添加就诊卡 */
    @RequireRoles(roles="casher")
    @PostMapping("add-card")
    @ApiOperation("添加就诊卡")
    public ServerResponse addCard(@RequestHeader("token")String token,@RequestBody @Validated Card card){
        UserOv userOv = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        if(card.getPatientName()==null){
            return new ServerResponse(ResponseCode.ERROR,"办卡人的姓名不能为空");
        }

        return cardService.addCard(card,userOv.getId());
    }


    //分页查询就诊卡
    @PostMapping("getCardList")
    @RequireRoles(roles="casher")
    public ServerResponse getCardList(@RequestHeader("token")String token, @RequestBody PageParam<Card> pageParam){
        //UserOv userOv = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return cardService.getCardList(pageParam);
    }

    //锁定
    @RequireRoles(roles="casher")
    @PostMapping("updateCardStatus1")
    public ServerResponse updateCardStatus1(@RequestHeader("token")String token,@RequestBody Card card){
       return cardService.updateCardStatus1(card);
    }

    //解锁
    @RequireRoles(roles="casher")
    @PostMapping("updateCardStatus2")
    public ServerResponse updateCardStatus2(@RequestHeader("token")String token,@RequestBody Card card){
        return cardService.updateCardStatus2(card);
    }

    //充值
    @RequireRoles(roles="casher")
    @PostMapping("updateCardMoney")
    public ServerResponse updateCardMoney(@RequestHeader("token")String token,@RequestBody Card card){
        return cardService.updateCardMoney(card);
    }

    //查看消费记录
    @RequireRoles(roles="casher")
    @PostMapping("getCostOutDetailList")
    public ServerResponse getCostOutDetailList(@RequestHeader("token")String token,@RequestBody PageParam<ConsumOv> pageParam){
        return cardService.getCostOutDetailList(pageParam);
    }
}
